from PyQt5.QtWidgets import QWidget, QPushButton, QMessageBox, QLineEdit, QTextEdit, QLabel, QMainWindow, QFileDialog
from PyQt5.QtCore import QRect, QCoreApplication
from info import user_info_jiams
from pdf_jm import pdf_encrypt


class PDF_Encrypt_UI_S(QMainWindow):
    def setupUi(self):
        self.resize(442, 172)
        self.centralwidget = QWidget()
        self.centralwidget.setObjectName(u"centralwidget")
        self.pushButton = QPushButton(self.centralwidget)
        self.pushButton.setObjectName(u"pushButton")
        self.pushButton.setGeometry(QRect(350, 10, 81, 61))
        self.pushButton.clicked.connect(self.pushButton_click)
        self.pushButton_2 = QPushButton(self.centralwidget)
        self.pushButton_2.setObjectName(u"pushButton_2")
        self.pushButton_2.setGeometry(QRect(350, 80, 81, 61))
        self.pushButton_2.clicked.connect(self.pushButton_2_click)
        self.label = QLabel(self.centralwidget)
        self.label.setObjectName(u"label")
        self.label.setGeometry(QRect(10, 40, 111, 111))
        self.label_2 = QLabel(self.centralwidget)
        self.label_2.setObjectName(u"label_2")
        self.label_2.setGeometry(QRect(10, 10, 101, 16))
        self.textEdit = QTextEdit(self.centralwidget)
        self.textEdit.setObjectName(u"textEdit")
        self.textEdit.setGeometry(QRect(130, 40, 211, 121))
        self.lineEdit = QLineEdit(self.centralwidget)
        self.lineEdit.setObjectName(u"lineEdit")
        self.lineEdit.setGeometry(QRect(130, 10, 211, 20))
        self.setCentralWidget(self.centralwidget)
        self.retranslateUi()
        # self.ProgressBar()

    def retranslateUi(self):
        self.setWindowTitle(QCoreApplication.translate("MainWindow", user_info_jiams, None))
        self.pushButton.setText(QCoreApplication.translate("MainWindow", u"\u6253\u5f00\u6587\u4ef6", None))
        self.pushButton_2.setText(QCoreApplication.translate("MainWindow", u"\u5f00\u59cb\u52a0\u5bc6", None))
        self.label.setText(QCoreApplication.translate("MainWindow", u"\u8bf7\u9009\u62e9\u9700\u8981\u52a0\u7684"
                                                                    u"\u6587\u4ef6:", None))
        self.label_2.setText(QCoreApplication.translate("MainWindow", u"\u8bf7\u8bbe\u7f6e\u52a0\u5bc6\u5bc6\u7801"
                                                                      u"\uff1a", None))

    def pushButton_click(self):
        self.textEdit.clear()
        file = QFileDialog.getOpenFileNames(self, "打开文件", "./", "PDF(*.pdf)")
        # 需要赋值过来，后面需要用该值
        self.file_list = file[0]
        # 将文件添加到textEidt中
        for i in self.file_list:
            self.textEdit.append(i)

    def pushButton_2_click(self):
        if self.textEdit.toPlainText() == '' or self.lineEdit.text() == '':
            self.msg = QMessageBox(QMessageBox.Warning, '警告', '未设置密码或未选择文件', QMessageBox.Ok)
        else:
            for file in self.file_list:
                pdf_encrypt(file, self.lineEdit.text())
            self.msg = QMessageBox(QMessageBox.Information, '提示', '加密完成', QMessageBox.Ok)
        self.msg.show()
